import axios from "axios";
import { ElLoading } from 'element-plus'
import { ElMessage } from 'element-plus'
let loading
const Service = axios.create({
    timeout: 3000,
    baseURL: "http://xxx",
    headers: {
        "Content-Type": "application/json;charset=utf-8"
    }
})

Service.interceptors.request.use(config => {
    loading = ElLoading.service({ fullscreen: true })
    return config
})

Service.interceptors.response.use(res => {
    loading.close()

    const data=res.data
    if(!data.data){
        ElMessage.error({message:data.msg,duration:2000})
    }
    if (res.code === 200) {
        return res;
    }
}, error => {
    loading.close()
    ElMessage.error({message:'服务器错误',duration:2000})
  
}
)
// post 请求
export const post=config=>{
    return Service({
        ...config,
        method:"post",
        data:config.data
    })
}

// get 请求
export const get=config=>{
    return Service({
        ...config,
        method:"get",
        data:config.data
    })
}

